package ugraph;

import static org.junit.Assert.*;

import java.util.Iterator;
import java.util.List;

import org.junit.Test;

public class ShipTest {

	//@Test
	public void testSpanTree() {
		Node n1= new Node("n1");
		Node n2= new Node("n2");
		Node n3= new Node("n3");
		Node n4= new Node("n4");
		Node n5= new Node("n5");
		Node n6= new Node("n6");
		
		Edge e1= new Edge(n1, n2, "e1");
		Edge e2= new Edge(n2, n3, "e2");
		Edge e3= new Edge(n3, n4, "e3");
		Edge e4= new Edge(n4, n1, "e4");
		Edge e5= new Edge(n4, n5, "e5");
		Edge e6= new Edge(n5, n6, "e6");
		Edge e7= new Edge(n6, n3, "e7");
		
		Ship ship= new Ship();
		ship.addNode(n1);
		ship.addNode(n2);
		ship.addNode(n3);
		ship.addNode(n4);
		ship.addNode(n5);
		ship.addNode(n6);
		ship.addEdge(e1);
		ship.addEdge(e2);
		ship.addEdge(e3);
		ship.addEdge(e4);
		ship.addEdge(e5);
		ship.addEdge(e6);
		ship.addEdge(e7);
		
		
		UGraph spant= ship.spanningTree();
		Iterator<Edge> i= spant.getEdges().iterator();
		while(i.hasNext()){
			System.out.println(i.next().name);
		}
		
	}
	
	//@Test
	public void testAdj(){
		Node n1= new Node("n1");
		Node n2= new Node("n2");
		Node n3= new Node("n3");
		Node n4= new Node("n4");	
		
		Edge e1= new Edge(n1, n2, "e1");
		Edge e2= new Edge(n2, n3, "e2");
		Edge e3= new Edge(n3, n4, "e3");
		Edge e4= new Edge(n4, n1, "e4");
		
		Ship ship= new Ship();
		
		ship.addNode(n1);
		ship.addNode(n2);
		ship.addNode(n3);
		ship.addNode(n4);
		ship.addEdge(e1);
		ship.addEdge(e2);
		ship.addEdge(e3);
		ship.addEdge(e4);
		
		Object[] node1= ship.list.get(n1).toArray();
		Object[] node2= ship.list.get(n2).toArray();
		Object[] node3= ship.list.get(n3).toArray();
		Object[] node4= ship.list.get(n4).toArray();
		System.out.println(node1[0] + " " + node1[1] + " " + n2 + " " +n4);
		System.out.println(node2[0] + " " + node2[1] + " " + n3 + " " +n1);
		System.out.println(node3[0] + " " + node3[1] + " " + n2 + " " +n4);
		System.out.println(node4[0] + " " + node4[1] + " " + n3 + " " +n1);
		System.out.println();
		ship.removeNode(n1);

		node2= ship.list.get(n2).toArray();
		node3= ship.list.get(n3).toArray();
		node4= ship.list.get(n4).toArray();
		System.out.println(node2[0] + " " + n3);
		System.out.println(node3[0] + " " + node3[1] + " " + n2 + " " +n4);
		System.out.println(node4[0] + " " + n3);
		System.out.println(ship.list.containsKey(n1));
	}
	
	//@Test
	public void testEdgeBetween(){
		Node n1= new Node("n1");
		Node n2= new Node("n2");
		Node n3= new Node("n3");
		Node n4= new Node("n4");	
		
		Edge e1= new Edge(n1, n2, "e1");
		Edge e2= new Edge(n2, n3, "e2");
		Edge e3= new Edge(n3, n4, "e3");
		Edge e4= new Edge(n4, n1, "e4");
		
		Ship ship= new Ship();
		
		ship.addNode(n1);
		ship.addNode(n2);
		ship.addNode(n3);
		ship.addNode(n4);
		ship.addEdge(e1);
		ship.addEdge(e2);
		ship.addEdge(e3);
		ship.addEdge(e4);
		
		//assertEquals(ship.edgeBetween(n1, n2), e1);
		//assertEquals(ship.edgeBetween(n2, n3), e2);
		//assertEquals(ship.edgeBetween(n3, n4), e3);
		//assertEquals(ship.edgeBetween(n4, n1), e4);
		//assertNull(ship.edgeBetween(n1, n3));
	}
	
	//@Test
	public void testGetPath(){
		Node n1= new Node("n1");
		Node n2= new Node("n2");
		Node n3= new Node("n3");
		Node n4= new Node("n4");
		//Node n5= new Node("n5");
		//Node n6= new Node("n6");
		//Node n7= new Node("n7");
		
		Edge e1= new Edge(n1, n2, "e1");
		Edge e2= new Edge(n2, n3, "e2");
		Edge e3= new Edge(n3, n4, "e3");
		Edge e4= new Edge(n1, n4, "e4");
		//Edge e1= new Edge(n1, n2, "e1");
		//Edge e2= new Edge(n2, n5, "e2");
		//Edge e3= new Edge(n5, n6, "e3");
		//Edge e4= new Edge(n4, n6, "e4");
		//Edge e5= new Edge(n3, n4, "e5");
		//Edge e6= new Edge(n3, n1, "e6");
		//Edge e7= new Edge(n4, n1, "e7");
		
		Ship ship= new Ship();
		
		ship.addNode(n1);
		ship.addNode(n2);
		ship.addNode(n3);
		ship.addNode(n4);
		//ship.addNode(n5);
		//ship.addNode(n6);
		//ship.addNode(n7);
		ship.addEdge(e1);
		ship.addEdge(e2);
		ship.addEdge(e3);
		ship.addEdge(e4);
		//ship.addEdge(e5);
		//ship.addEdge(e6);
		//ship.addEdge(e7);
		
		List<Edge> list= ship.getPath(n1, n3);
		//System.out.println(list==null);
		Iterator<Edge> i= list.iterator();
		while(i.hasNext()){
			System.out.println(i.next().name);
		}
	}
	
	
	

}
